package com.neusoft.elm.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import com.neusoft.elm.po.Business;
import com.neusoft.elm.service.BusinessService;
import com.neusoft.elm.service.impl.BusinessServiceImpl;

public class BusinessController {
	public Object listBusinessByOrderTypeId(HttpServletRequest request) throws Exception {
		Integer orderTypeId = Integer.valueOf(request.getParameter("orderTypeId"));
		BusinessService service = new BusinessServiceImpl();
		List<Business> list = service.listBusinessByOrderTypeId(orderTypeId);
		return list;
	}

	public Object getBusinessById(HttpServletRequest request) throws Exception {
		Integer businessId = Integer.valueOf(request.getParameter("businessId"));
		BusinessService service = new BusinessServiceImpl();
		Business business = service.getBusinessById(businessId);
		return business;
	}

	public List<Business> searchBusiness(HttpServletRequest request) throws Exception {
		String keyword = request.getParameter("keyword");
		BusinessService service = new BusinessServiceImpl();
		if (keyword != null && !keyword.isEmpty()) {
			return service.searchBusinessByName(keyword);
		}
		return null; // 或者返回一个空列表，或者抛出一个异常
	}

	public Object createBusiness(HttpServletRequest request) {
		int res = 1;
		BusinessService service = new BusinessServiceImpl();
		Business business = new Business();
		business.setBusinessName(request.getParameter("businessName"));
		business.setBusinessAddress(request.getParameter("businessAddress"));
		business.setBusinessExplain(request.getParameter("businessExplain"));
		business.setBusinessImg(request.getParameter("businessImg"));
		business.setOrderTypeId(Integer.parseInt(request.getParameter("orderTypeId")));
		business.setStarPrice(Double.parseDouble(request.getParameter("starPrice")));
		business.setDeliveryPrice(Double.parseDouble(request.getParameter("deliveryPrice")));
		business.setRemarks(null);

		service.addBusiness(business);
		return  res;
	}
}